package com.csy.user.controller.system;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.csy.commons.core.controller.BaseController;
import com.csy.commons.core.domain.BaseResponse;
import com.csy.commons.core.page.PageResult;
import com.csy.user.entity.system.domain.SysNotice;
import com.csy.user.entity.system.service.SysNoticeService;

/**
 * 通知公告
 */
@RestController
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController {

    @Resource
    private SysNoticeService sysNoticeService;

    /**
     * 查询通知公告集合
     * @param sysNotice
     * @return
     */
    @GetMapping("/list")
    public PageResult list(SysNotice sysNotice){
        startPage();
        List<SysNotice> list = sysNoticeService.selectNoticeList(sysNotice);
        return getData(list);

    }

    /**
     * 查询通知信息
     * @param noticeId
     * @return
     */
    @GetMapping(value = "/{noticeId}")
    public BaseResponse<SysNotice> getInfo(@PathVariable Long noticeId){
        return BaseResponse.success(sysNoticeService.selectNoticeById(noticeId));
    }

    /**
     * 新增
     * @param sysNotice
     * @return
     */
    @PostMapping
    public BaseResponse<Integer> add(@RequestBody SysNotice sysNotice) {
        int row = sysNoticeService.addNotice(sysNotice);
        return toAjax(row);
    }

    /**
     * 更新
     * @param sysNotice
     * @return
     */
    @PutMapping
    public BaseResponse<Integer> update(@RequestBody SysNotice sysNotice){
        return toAjax(sysNoticeService.update(sysNotice));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    private BaseResponse<Integer> del(@PathVariable("id")String id){
        int row = sysNoticeService.deleteById(id);
        return toAjax(row);
    }

}
